package com.zhuojy.equity.mall.admin.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuojy.equity.mall.admin.common.entity.Document;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.service.DocumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("document")
@RequiredArgsConstructor
@Api(tags = "文档管理")
public class DocumentController {
    private final DocumentService documentService;
    @ApiOperation(value = "文档管理，分页查询", httpMethod = "POST", notes = "文档管理列表分页查询")
    @RequestMapping("queryDocument")
    public ResultEntity queryRecruitment(
            @RequestBody Document document ,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        try {
            IPage page = documentService.queryRecruitment(document,pageNum,pageSize);
            return ResultEntity.OK(page);
        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }
    @ApiOperation(value = "文档管理，分页查询", httpMethod = "POST", notes = "文档管理列表分页查询")
    @RequestMapping("queryDocument2")
    public ResultEntity queryRecruitment2(
            @RequestBody Document document){
        try {
            IPage page = documentService.queryRecruitment2(document);
            return ResultEntity.OK(page);
        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("deleteDocument")
    public  ResultEntity deleteDocument(@RequestParam("id") Integer id ){
        try {
            documentService.deleteDocument(id);
            return ResultEntity.OK("删除成功");
        } catch (Exception e) {
          e.printStackTrace();
            return ResultEntity.ERROR(e.getMessage());
        }
    }

    /**
     * 修改
     * @param document
     * @return
     */
    @RequestMapping("updateDocument")
    public  ResultEntity updateDocument(@RequestBody Document document){
        try {
            documentService.updateDocument(document);
            return ResultEntity.OK("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR(e.getMessage());
        }
    }
}
